package top.fzqblog.Utils;

import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

/**
 * Created by 抽离 on 4047/9/5 0005.
 */
public class SaiZiUtil {
    
    public static Integer[] getSaiZiResult(){
        int n;
        Integer num[]={0,0,0,0,0,0};
        for(int i=0;i<6;i++){
            n=1+(int)(Math.random()*5);
            num[i] = n;
        }
        return num;
    }

    public static int getSameCount(Integer[] result, int theNum){
        int n = 0;
        for (Integer num : result) {
            if(num == theNum){
                n ++;
            }
        }
        return  n;
    }

    public static int getSameSize(Integer[] result){
        Set<Integer> set = new HashSet<>();
        set.addAll(Arrays.asList(result));
        return set.size();
    }

    public static String getSaiZiType(Integer[] result){
//        System.out.println("：" + Arrays.toString(result));
        int count1 = getSameCount(result, 1);
        int count2 = getSameCount(result, 2);
        int count3 = getSameCount(result, 3);
        int count4 = getSameCount(result, 4);
        int count5 = getSameCount(result, 5);
        int count6 = getSameCount(result, 6);
        int size = getSameSize(result);
        if(count4 == 6){
            return "六杯红";
        }
        else if(size == 1){
            return "六杯黑";
        }
        else if(size == 2 && count4 == 5){
            return "五王";
        }
        else if(size==2 && count4 == 4 && count1 == 2){
            return "状元插金花";
        }
        else if(size == 2 && (count1 == 5 || count2 ==5 || count3 == 5 || count5 == 5 || count6 == 5)){
            return "五子登科";
        }
        else if(count4 == 4){
            return "状元";
        }
        else if(count1==4 || count2 == 4 || count3 == 4 || count5 == 4 || count6 == 4){
            return "四进士";
        }
        else if(count4 == 3){
            return "三红";
        }
        else if(count4 == 2){
            return "二举";
        }
        else if(count4 == 1){
            return "一秀";
        }
        else if(result[0]==1 && result[2]==2 && result[3]==3 &&
                result[4]==4 && result[5]==5 && result[6]== 6
                ){
            return "对堂";
        }
        return "不中奖";
    }

    public static Integer[]  RandomSaiZi(){
        Integer[] result = getSaiZiResult();
        String rel = getSaiZiType(result);
        int i = 0;
        while (!rel.equals("不中奖") && i < 2){
            result = getSaiZiResult();
            rel = getSaiZiType(result);
            i++;
        }
        return result;
    }

    public static Integer getCredits(String type){
        switch (type){
            case "不中奖":
                return 0;
            case "一秀":
                return 1;
            case "二举":
                return 2;
            case "四进士":
                return 3;
            case  "三红":
                return 4;
            case "对堂":
                return 5;
            case "状元":
                return 6;
            case "五子登科":
                return 7;
            case "五王":
                return 8;
            case "状元插金花":
                return 9;
            case "六杯黑":
                return 10;
            case "六杯红":
                return 10;
            default:
                return 0;
        }
    }

    public static void main(String[] args){
        Integer[] resultarr = SaiZiUtil.RandomSaiZi();
        String resultname = SaiZiUtil.getSaiZiType(resultarr);
        System.out.println("：" + resultarr + ":" + resultname);
    }
}
